
# 案例：全选 + 复制 + 粘贴等

from time import sleep

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys

# 输入用户名
driver = webdriver.Firefox()
driver.get('http://localhost/myweb/jxc/index.asp')
u_name = driver.find_element_by_name('username')
u_name.send_keys('admin')


# 全选用户名的输入：  Ctrl A
#  功能键的模拟必须两步走，先按下，再抬起
#   1. 按下 Ctrl 键
#   2. 按下 A 键
#   3. 抬起 Ctrl 键

# 全选
ActionChains(driver).move_to_element(u_name).\
    key_down(Keys.CONTROL)\
    .send_keys('A').\
    key_up(Keys.CONTROL).\
    perform()

# 剪切
ActionChains(driver).move_to_element(u_name).\
    key_down(Keys.CONTROL)\
    .send_keys('X').\
    key_up(Keys.CONTROL).\
    perform()

# 先输入ok，再进行粘贴
ActionChains(driver).move_to_element(u_name).\
    send_keys('ok').\
    key_down(Keys.CONTROL)\
    .send_keys('V').\
    key_up(Keys.CONTROL).\
    perform()


